package com.googlecode.openrtp.grizzly;

import com.google.inject.Singleton;
import com.google.inject.name.Named;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import javax.inject.Inject;

/**
 *
 * @author jocke
 */
@Singleton
public class ThreadResources {

    private final ExecutorService cachedExecutorService;
    private final ExecutorService fixedExecutorService;
    private final ScheduledExecutorService scheduledThreadPool;

    @Inject
    public ThreadResources(@Named("threadPoolSize") int size) {
        cachedExecutorService = Executors.newCachedThreadPool();
        fixedExecutorService = Executors.newFixedThreadPool(size);
        scheduledThreadPool = Executors.newScheduledThreadPool(size);
    }

    public ExecutorService getCachedExecutorService() {
        return cachedExecutorService;
    }

    public ExecutorService getFixedExecutorService() {
        return fixedExecutorService;
    }

    public ScheduledExecutorService getScheduledThreadPool() {
        return scheduledThreadPool;
    }

    public void shutdownNow() {
        cachedExecutorService.shutdownNow();
        fixedExecutorService.shutdownNow();
        scheduledThreadPool.shutdownNow();
    }
}
